<?php


namespace app\library\create\lib;


class CreateController
{
    public static function buildFile(string $name, string $prefix)
    {
        $commonControllerFile = root_path('app/library/template') . 'CommonController.template';
        $str = file_get_contents($commonControllerFile);
        $str = str_replace('modelName', $name, $str);
        $str = str_replace('controllerName', $name, $str);
        $file = "$name.php";
        $path = root_path('app/admin/controller');
        CreateFile::createFile($path, $file, $str); //生成文件
        //创建baseController
        if (!file_exists($path . 'BaseController.php')) {
            $baseControllerFile = root_path('app/library/template') . 'BaseController.template';
            $str = file_get_contents($baseControllerFile);
            $file = "BaseController.php";
            CreateFile::createFile($path, $file, $str);
        }
    }

}